package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Brand;
import com.mall.db.service.BrandService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/brand/bc")
public class BrandController extends BaseController<Brand>{
    @Resource(name = "brandService")
    private BrandService bs;
    @Override
    @OperationLog(value = "查询品牌商家",type = 0)
    public Map<String, Object> find(Brand brand) {
        PageHelper.startPage(brand.getPage(),brand.getLimit());
        QueryWrapper<Brand> qw=new QueryWrapper<>();
        if (!StringUtils.isEmpty(brand.getBrandId())){
            qw.eq("brand_id",brand.getBrandId());
        }
        if (!StringUtils.isEmpty(brand.getTitle())){
            qw.eq("title",brand.getTitle());
        }
        List<Brand> list=bs.list(qw);
        PageInfo<Brand> page=new PageInfo<>(list,brand.getLimit());
        return this.findMap(page.getList(),page.getTotal());
    }

    @Override
    @OperationLog(value = "新增品牌商家",type = 0)
    public Map<String, Object> add(Brand brand) {
        boolean b=bs.save(brand);
        return this.iud("新增",b,brand);
    }


    @Override
    @OperationLog(value = "编辑品牌商家",type = 0)
    public Map<String, Object> update(Brand brand) {
        boolean b=bs.updateById(brand);
        return this.iud("编辑",b,brand);
    }

    @Override
    @OperationLog(value = "删除品牌商家",type = 0)
    public Map<String, Object> delete(Brand brand) {
        QueryWrapper<Brand> qw=new QueryWrapper<>();
        qw.eq("id",brand.getId());
        boolean b=bs.remove(qw);
        return this.iud("删除",b,brand);
    }
    
}
